<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
    <style>
      ul li {
        border: 1px solid #000;
        display: inline-block;
        width: 100px;
        background-color: aqua;
        color: gold;
        font-size: 22px;
      }

      .picbox {
        width: 300px;
        display: none;
      }

      .active {
        display: block;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <ul>
        <li v-for="(item,index) in pics" @click="change(index)">
          {{item.title}}
        </li>
      </ul>
      <div
        v-for="(item,index) in pics"
        :class="['picbox',{'active': currentIndex == index ? true : false}]"
      >
        <img :src="item.imgSrc" alt="" />
      </div>

      <input type="text" placeholder="title" v-model="title" />
      <input type="text" placeholder="imgSrc" v-model="imgSrc" />
      <button @click="addPic">click</button>
    </div>
    <script src="./vue.js"></script>
    <script>
      var vm = new Vue({
        el: "#app",
        data: {
          currentIndex: 0,
          title: "",
          imgSrc: "",
          pics: [
            {
              title: "img1",
              imgSrc: "img/1.png",
            },
            {
              title: "img2",
              imgSrc: "img/2.png",
            },
            {
              title: "img3",
              imgSrc: "img/3.png",
            },
          ],
        },
        methods: {
          change(i) {
            this.currentIndex = i;
          },
          addPic() {
            let obj = {
              title: this.title,
              imgSrc: this.imgSrc,
            };
            //   this.pics.push(obj)
            //    this.$set(this.pics,this.pics.length,obj)
            Vue.set(this.pics, this.pics.length, obj);
          },
        },
      });
    </script>
  </body>
</html>
